//
//  ImageReportCell.m
//  yilutongxing
//
//  Created by T&J on 2017/12/6.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "ImageReportCell.h"

@interface ImageReportCell()
@property (strong, nonatomic) IBOutlet UIImageView *img1;
@property (strong, nonatomic) IBOutlet UIImageView *img2;
@property (strong, nonatomic) IBOutlet UIImageView *img3;

@property (strong, nonatomic) NSArray *imgview_arr;
@end

@implementation ImageReportCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)fillImages:(NSArray *)images{
    [_img1 setImage:nil];
    [_img2 setImage:nil];
    [_img3 setImage:nil];
    for (int i=0; i<images.count && i<self.imgview_arr.count; i++) {
        [((UIImageView*)self.imgview_arr[i]) setImage:(UIImage*)images[i]];
    }
}

- (void)fillImagesForUrl:(NSString *)urlStr{
    [_img1 setImage:nil];
    [_img2 setImage:nil];
    [_img3 setImage:nil];
    NSMutableArray *urlArr = [[urlStr componentsSeparatedByString:@","] mutableCopy];
    NSEnumerator *reveren = [urlArr reverseObjectEnumerator];
    NSString *url = nil;
    while (url = [reveren nextObject]) {
        if (![url isNotEmpty]) {
            [urlArr removeObject:url];
        }
    }
    NSMutableArray *img_arr = [NSMutableArray array];
    for (int i=0; i<urlArr.count && i<self.imgview_arr.count; i++) {
        UIImageView *imgv = self.imgview_arr[i];
        [imgv sd_setImageWithURL:[NSURL URLWithString:urlArr[i]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if (image) {
                [img_arr addObject:image];
                if (img_arr.count==urlArr.count && self.delegate && [self.delegate respondsToSelector:@selector(sendImgs:forIndex:)]) {
                    [self.delegate sendImgs:img_arr forIndex:self.current_indexpath];
                }
            }
        }];
    }
}

- (NSArray *)imgview_arr{
    if (!_imgview_arr) {
        _imgview_arr = @[_img1, _img2, _img3];
    }
    return _imgview_arr;
}

@end
